package com.example.big_event.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.big_event.Utils.Md5Util;
import com.example.big_event.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.example.big_event.pojo.entity.User;
import com.example.big_event.service.UserService;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Autowired
    private UserMapper userMapper;

    /**
     * 通过用户名找到用户
     * @param username 用户名
     * @return 对应的用户或者null（没找到）
     */
    @Override
    public User findByUserName(String username) {
       LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
       queryWrapper.eq(User::getUsername ,username);
        return userMapper.selectOne(queryWrapper);
    }


    /**
     * 注册方法
     * @param username 用户名
     * @param password 密码
     */
    @Override
    public void register(String username, String password) {
        // 将密码进行加密后进行添加到数据库
        userMapper.insert(new User
                (username, Md5Util.Md5Encrypt(password)));
    }
}
